/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package foalvleditor.core.impl;

import foalvleditor.gameobjects.AbstractGameObject;
import java.util.ArrayList;

/**
 *
 * @author Mikael
 */
public final class ClipboardModel {

    private ArrayList<AbstractGameObject> clipboard= new ArrayList<AbstractGameObject>();
    private UndoModel undoModel=UndoModel.getInstance();
    private LevelModel levelModel=LevelModel.getInstance();

    private static ClipboardModel instance=new ClipboardModel();

    public static ClipboardModel getInstance(){
        return instance;
    }
    public boolean clipboardEmpty(){
        return clipboard.isEmpty();
    }

    @SuppressWarnings("unchecked")
	public ArrayList<AbstractGameObject> getClipboard(){
    	return (ArrayList<AbstractGameObject>) clipboard.clone();
    }

    public boolean clipboardContainsPlayer(){
        for (int i=0; i<clipboard.size(); i++)
        {
            if (clipboard.get(i).getName().contains("Player"))
            {
                return true;
            }
        }
        return false;
    }

    public void copyToClipboard(AbstractGameObject goa) {
        this.clipboard.clear();
        try{
        this.clipboard.add(goa.clone());
        }
        catch (CloneNotSupportedException e){
            this.clipboard.add(goa);
        }
    }

    @SuppressWarnings("unchecked")
	public void copyToClipboard(ArrayList<AbstractGameObject> goa) {
        ArrayList<AbstractGameObject> clone = (ArrayList<AbstractGameObject>) goa.clone();
		this.clipboard=clone;
    }

    public void pasteFromClipboard() {
        if (!clipboardEmpty())
        {
            undoModel.addUndoElement();
            for (int i=0; i<clipboard.size(); i++)
            {
              try{
                levelModel.addObject(getClipboard().get(i).clone());
                }
           catch (CloneNotSupportedException e){
                 levelModel.addObject(getClipboard().get(i));
             }
            }
          levelModel.getView().repaintAll();
        }
    }
}

